package com.jdzy.student.controller;

import com.jdzy.model.common.vos.ResultA;
import com.jdzy.model.common.vos.ResultCodeEnum;
import com.jdzy.model.teacher.pojos.SysMenu;
import com.jdzy.student.service.SysMenuService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@Api(value = "菜单的controller类")
@CrossOrigin(allowCredentials = "true" , allowedHeaders = "*")
@RequestMapping(value = "/api/system/sysMenu")
public class SysMenuController {
    @Autowired
    private SysMenuService sysMenuService;
    // 菜单管理

    /**
     * 查找菜单节点
     * @return
     */
    @GetMapping(value = "/findNodes")
    public ResultA<List<SysMenu>> findNodes(){
        List<SysMenu> list = sysMenuService.findNodes();
        return  ResultA.build(list, ResultCodeEnum.SUCCESS);
    }

    //添加菜单
    @PostMapping(value = "/save")
    public ResultA save(@RequestBody SysMenu sysMenu){
        sysMenuService.saveMenu(sysMenu);
        return ResultA.build(null, ResultCodeEnum.SUCCESS);
    }
    //修改菜单
    @PutMapping(value = "/update")
    public ResultA updateMenuById(@RequestBody SysMenu sysMenu){
        sysMenuService.updateMenuById(sysMenu);
        return ResultA.build(null, ResultCodeEnum.SUCCESS);
    }
    //删除菜单
    @DeleteMapping(value = "/removeById/{id}")
    public ResultA removeById(@PathVariable Long id){
        sysMenuService.removeById(id);
        return ResultA.build(null, ResultCodeEnum.SUCCESS);
    }
}
